import { _decorator, Component, director, Button } from "cc";
const { ccclass, property } = _decorator;
import { native } from "cc";

@ccclass("Restart")
export class Restart extends Component {
  protected start(): void {
    this.node.on(Button.EventType.CLICK, () => {
      // @ts-ignore
      window.playAgainWatchAdVideoCallback = () => {
        director.loadScene("game");
        // @ts-ignore
        window.playAgainWatchAdVideoCallback = null;
      };

      native.reflection.callStaticMethod(
        "com/cocos/game/AppActivity",
        "playAgainWatchAdVideo",
        "(Ljava/lang/String;)V",
        "playAgainWatchAdVideoCallback"
      );
      // if (
      //   window &&
      //   window.Android_Color &&
      //   window.Android_Color.playAgainWatchAdVideo
      // ) {
      //   // 回调函数
      //   // @ts-ignore
      //   window.playAgainWatchAdVideoCallback = () => {
      //     director.loadScene("game");
      //     // @ts-ignore
      //     window.playAgainWatchAdVideoCallback = null;
      //   };
      //   window.Android_Color.playAgainWatchAdVideo(
      //     "playAgainWatchAdVideoCallback"
      //   );
      // } else {
      //   director.loadScene("game");
      // }
    });
  }
}
